/**
 * Copyright (c) 2010 - 2012, Sina Inc. All rights reserved.
 * @fileoverview    创建专题
 * @author bowen liu
 * @email liubowen082@163.com
 * @version 1.0
 */

//引用配置文件
//$require('cpt.LJSDefine');
//$require('cpt.collectionTop');

$require('cpt.LJSDefine');
$require('cpt.modDefineValue');
$require('form.cFormTitle');
$require('form.cFormTextarea');
$require('cpt.uploadPic');
//$require('mod.uploadFlv');
$require('form.cFormUrl');
$require('mod.cAlert')
LJS.define('page.createPro',function(ljs){
    
	
	
	var bries = $('[node_type="briefing"]'),titles=[],urls = [],areas = [];
	window.uploads = []
	var uploadForms = $('[node_type="fileForm"]');
	$.each(bries,function(i,a){
		
		
		
		
					var upload = new ljs.cpt.uploadPic({
									   uploadBox : a,
									   uploadForm : uploadForms[i]
									   });
//					var upload = new ljs.mod.uploadFlv({
//						box:$(a),
//						objectName:'window.uploads['+i+']'
//					})
					$(upload).on('uploadSuc',function(evt,data){
								$('[node_type="imgId"]' ,a).val(data.content[0].id)
								$('[node_type="imgSrc"]',a).attr('src',data.content[0].url)
									  })
					$(upload).on('uploadErr',function(evt,data){
										ljs.mod.cAlert({txt:data.msg})			
													  })
					uploads.push(upload);
					
					
					
					
					
					
					
					
					titles.push(new ljs.form.cFormTitle({
							'el': $('[node_type="title"]',a)[0],
							'arrow':'down',
							'require': ['focus', 'blur']
						}));
					
					urls.push(new ljs.form.cFormUrl({
							'el': $('[node_type="url"]',a)[0],
							'arrow':'down',
							'require': ['focus', 'blur']
						}));
					areas.push(new ljs.form.cFormTextarea({
							'el': $('[node_type="textarea"]',a)[0],
							'arrow':'down',
							'require': ['focus', 'blur']
						}));
					
						  
						  })

	
	$('#submitBtn').on('click',function(){
		var isError = false
						$('#createError').hide();
						$.each($('[node_type="imgId"]'),function(i,a){
																 //console.log($(a).val()=='')
													//console.log($(a).val()==$(a).attr('defineValue'))			 
								if($(a).val()==''||$(a).val()==$(a).attr('defineValue')){
									isError = true
									return false
									}
								});
						if(isError){
							$('#createError').show();
							return
							}
						var errorTitle = null
						$.each(titles,function(i,a){
								if(!a.check()){
									isError = true
									errorTitle = a
									return false
									}
								});
						if(isError){
							$('#createError').show();
							errorTitle.showError()
							return 
							}
						
						$.each(urls,function(i,a){
								if(!a.check()){
									isError = true
									errorTitle = a
									return false
									}
								});
						if(isError){
							$('#createError').show();
							errorTitle.showError()
							return
							}
						$.each(areas,function(i,a){
								if(!a.check()){
									isError = true
									errorTitle = a
									return false
									}
								});
						if(isError){
							$('#createError').show();
							errorTitle.showError()
							return
							}
						$('#postsForm').submit();
						
						})
	
})

